$package('itsm.business');

itsm.business.sellIng=function(){
	this.opt='';
	return {
		//列表
		sellIngGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'sell!findSellPage.action?sellQueryDTO.searchType=MatchIng&sellQueryDTO.multipleStatus=0&sellQueryDTO.multipleStatus=1',
				caption:'挂牌卖出列表',
				colNames:['ID','卖出会员','姓名','挂出时间','卖出股数','卖出股价','状态','匹配日期','未卖出股数','优先级','买入时的股价','类型','备注'],
			 	colModel:[
			 	          {name:'id',align:'center',width:80},
			 	          {name:'sellUser',align:'center',width:100},
			 	          {name:'sellUserName',align:'center',hidden:true},
			 	          {name:'createTime',align:'center',formatter:timeFormatter},
			 	          {name:'sellMoney',align:'center'},	
			 	          {name:'sellPrice',align:'center'},
			 	          {name:'status',align:'center',formatter:itsm.business.sellIng.statusFormatter},
			 	          {name:'matchTime',align:'center',formatter:timeFormatter},
			 	          {name:'surplusMoney',align:'center'},
			 	          {name:'priority',align:'center'},
			 	          {name:'buyPrice',align:'center'},
			 	          {name:'sellType',align:'center',formatter:itsm.business.sellIng.typeFormatter,hidden:true},
			 	          {name:'remark',align:'left'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'id',
				toolbar:[true,"top"],
				sortorder:'desc',
				rowNum:20, 
				rowList:[10,20,50],
				pager:'#sellIngPager'
				});
				$("#sellIngGrid").jqGrid(params);
				$("#sellIngGrid").navGrid('#sellIngPager',navGridParams);
				//列表操作项
				$("#t_sellIngGrid").css(jqGridTopStyles);
				$("#t_sellIngGrid").html($('#sellIngGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#sellIngGrid","regCenter",10);
		},
		statusFormatter:function(v1,v2,v3){
			if(v1=='0'){
				return "<span style='color:#0000EE'>排队中</span>";
			}
			if(v1=='1'){
				return "<span style='color:#8A2BE2'>匹配成功</span>";
			}
			if(v1=='2'){
				return "<span style='color:#228B22;'>交易成功</span>";
			}
			if(v1=='3'){
				return "<span style='color:#EEC900;'>已取消</span>";
			}
		},
		typeFormatter:function(v1,v2,v3){
			if(v1=='Static'){
				return "静态";
			}else{
				return "动态";
			}
		},
		
		changeOrder:function(v1,v2,v3){
			checkBeforeEditGrid('#sellIngGrid',function(rowData){
				$('#sell_id').val(rowData.id);
				$('#sell_priority').val(rowData.priority);
				$('#sell_createDate').val(rowData.createTime);
				$('#changeOrder_win').window('open');
			});	
		},
		
		changeOrderOpt:function(){
			var _param = $('#changeOrder_form').serialize();
			$.post('sell!changeOrder.action',_param,function(data){
				msgShow('更新成功!','show');
				$('#changeOrder_win,#editSellOrder_win').window('close');
				$('#sellIngGrid').trigger('reloadGrid');
			})
		},
		
		//搜索
		search:function(){
			var sdata=$('#sell_search_form').getForm();
			var postData = $("#sellGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'sell!findSellPage.action';
			$('#sellGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		addSell:function(){
			$('#addSell_win').window('open');
		},
		addSellOpt:function(){
			var _param = $('#addSell_form').serialize();
			$.post('sell!sellBack.action',_param,function(data){
				msgShow('新增成功!','show');
				$('#addSell_win').window('close');
				$('#sellIngGrid').trigger('reloadGrid');
			})
		},
		
		editSellOrder:function(v1,v2,v3){
			checkBeforeEditGrid('#sellIngGrid',function(rowData){
				$('#editsell_id').val(rowData.id);
				$('#sell_sellMoney').val(rowData.sellMoney);
				$('#sell_sellPrice').val(rowData.sellPrice);
				$('#editSellOrder_win').window('open');
			});	
		},
		editOrderOpt:function(){
			var _param = $('#editSellOrder_form').serialize();
			$.post('sell!changeOrder.action',_param,function(data){
				msgShow('更新成功!','show');
				$('#editSellOrder_win').window('close');
				$('#sellIngGrid').trigger('reloadGrid');
			})
		},
		
		init:function(){
			itsm.business.sellIng.sellIngGrid();
		}
	}
	
}();

$(function(){
	itsm.business.sellIng.init();
});